#include <mysql/mysql.h>
#include <stdio.h>
#include <string.h>
int getPasswdByUserName(char *userName,char *passwd)
{
    MYSQL *conn;
    MYSQL_RES *res;
    MYSQL_ROW row;
    const char* server="localhost";//？？？？
    const char* user="root";
    const char* password="123";
    const char* database="myCloud_user";//要访问的数据库名称
    char query[300]="select passwd from passwd where userName =";

    sprintf(query, "%s\"%s\"", query, userName);

    puts(query);

    unsigned int t;
    conn=mysql_init(NULL);
    if(!mysql_real_connect(conn,server,user,password,database,0,NULL,0))
    {
        printf("Error connecting to database:%s\n",mysql_error(conn));
        return -1;
    }else{
        printf("Connected...\n");
    }
    t=mysql_query(conn,query);
    if(t)
    {
        printf("Error making query:%s\n",mysql_error(conn));
    }else{
        printf("t: %d\n",t);
        res = mysql_use_result(conn);
        if(res)
        {
            printf("res is not null\n");
            row = mysql_fetch_row(res);
            if(row)
            {
                printf("row :%s\n", row[0]);
                strcpy(passwd, row[0]);
            }
            else
            {
                printf("data not found\n");
            }
            mysql_free_result(res);
            mysql_close(conn);
            return 0;
        }
        else
        {
            printf("err in mysql_use_result\n");
            mysql_close(conn);
            return -1;
        }
    }
}
       